import request from '@/utils/request'

// 分页搜索菜品
export function searchDishes(params) {
  return request({
    url: '/dish/search',
    method: 'get',
    params
  })
}

// 获取所有菜品（分页）
export function getAllDishes(params) {
  return request({
    url: '/dish/search',
    method: 'get',
    params: {
      pageNum: params.pageNum || 1,
      pageSize: params.pageSize || 12,
      keyword: params.keyword || '',
      ...params
    }
  })
}

// 获取店铺菜品列表
export function getDishesByStore(params) {
  return request({
    url: '/dish/list',
    method: 'get',
    params
  })
}

// 获取菜品详情
export function getDishDetail(dishId) {
  return request({
    url: '/dish/detail',
    method: 'get',
    params: { dishId }
  })
}

// 添加菜品
export function addDish(data) {
  return request({
    url: '/dish/add',
    method: 'post',
    data
  })
}

// 更新菜品
export function updateDish(data) {
  return request({
    url: '/dish/update',
    method: 'post',
    data
  })
}

// 删除菜品
export function deleteDish(dishId) {
  return request({
    url: '/dish/delete',
    method: 'delete',
    params: { dishId }
  })
}

// 上传菜品图片
export function uploadDishImage(file) {
  return request({
    url: '/dish/upload',
    method: 'post',
    data: file,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
